package com.wm.practice;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName: DaemonDemo
 * @Description: 用户线程和守护线程的练习
 * @Author: Deamer
 * @Date: 2022/8/28 8:40
 **/
public class DaemonDemo {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t开始运行，" + (Thread.currentThread().isDaemon() ? "守护线程" : "用户线程"));
            while (true) {

            }
        }, "t1");
        // 线程的daemon属性为true表示是守护线程，false表示是用户线程
//        t1.setDaemon(true);
        t1.start();
        // 3s后主线程再运行
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("-----------main线程运行完毕！");
    }
}
